package fasilkom.antz;

import java.awt.Graphics2D;
import java.awt.event.KeyEvent;

import com.golden.gamedev.GameObject;
import com.golden.gamedev.engine.timer.SystemTimer;
import com.golden.gamedev.object.GameFont;
import com.golden.gamedev.object.Sprite;
import com.golden.gamedev.object.background.ImageBackground;

public class PostLevel extends GameObject {
	
	ImageBackground background;
	
	Sprite pointer;
	SystemTimer timer;
	Long time;
	String[] pic;
	int counter;
	
	int type;
	
	public PostLevel(Antz parent) {
		super(parent);
	}
	
	public void initResources() {
		pic = new String[4];
		counter = 0;
		for(int i = 0 ; i < pic.length ; i++){
			pic[i] = "assets/" + (i+21) + ".jpg";
		}
		
		background = new ImageBackground(getImage(pic[0]));
		timer = new SystemTimer();
		timer.setFPS(getFPS());
		timer.startTimer();
		time = timer.getTime();
		/*pointer = new Sprite(getImage("assets/pointer2.png"));
		pointer.setBackground(background);
		pointer.setLocation(300, 305);*/
		
		// Hide the mouse pointer
		bsInput.setMouseVisible(false);
	}
	
	public void render(Graphics2D g) {
		background.render(g);
		
		GameFont font = fontManager.getFont(getImages
				("assets/font-small.png", 13, 6), "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789   .,;:!?\"-/&`' ");
		font.drawString(g, "Tekan spasi untuk melanjutkan", 10, getHeight() - 20);
	}
	
	public void update(long elapsedTime){
		background.update(elapsedTime);
		if(timer.getTime() - 5000 >= time || keyPressed(KeyEvent.VK_SPACE)){
			if(counter == pic.length){
				parent.stop();
			}
			background.setImage(getImage(pic[counter]));
			time = timer.getTime();
			counter++;
		}
		
		if(keyPressed(KeyEvent.VK_ENTER)){
			parent.nextGameID = Antz.WORLD_MAP;
			finish();
		}
	}
}
